<script setup>
import bg from '@/assets/img/bg.png'
import { ref, onMounted } from "vue";
import { useRouter } from "vue-router";
import { merchantApi } from "@/api";

const router = useRouter();
const recordList = ref([]);
const totalCount = ref(0);
const totalAmount = ref(0);
const todayCount = ref(0);
const todayAmount = ref(0);

// 模拟数据，实际项目中应该从API获取
onMounted(() => {
  // 模拟API调用
  // 实际项目中应该使用 couponApi.getRecords() 获取数据
  const uid = localStorage.getItem("uid");
  merchantApi
    .getRecordList({
      uid: uid,
      pageNum: 1,
      pageSize: 1000,
    })
    .then((res) => {
      console.log(res);
      recordList.value = res.data;
      todayCount.value = res.todayCheckNum || 0;
      todayAmount.value = res.todayCheckSum || 0;
      totalCount.value = res.totalCheckNum || 0;
      totalAmount.value = res.totalCheckSum || 0;
    });
});
</script>
<template>
  <div class="records-container" :style="{background: `url('${bg}')`}">
    <!-- 统计数据 -->
    <div class="statistics">
      <div class="stat-numbers">
        <div class="today-count">
          <div class="stat-item">
            <img src="@/assets/img/total-count.png" />
            <div class="stat-text">累计{{ totalCount }}张</div>
          </div>
          <div class="number">{{ todayCount }}</div>
          <div class="label">今日消费券数(张)</div>
        </div>
        <div class="divider"></div>
        <div class="today-amount">
          <div class="stat-item">
            <img src="@/assets/img/total-amount.png" />
            <div class="stat-text">累计{{ totalAmount }}元</div>
          </div>
          <div class="number">{{ todayAmount }}</div>
          <div class="label">今日核销金额(元)</div>
        </div>
      </div>
    </div>

    <!-- 记录明细 -->
    <div class="record-details">
      <div class="detail-title">核销记录明细</div>

      <div class="record-list" v-if="recordList.length > 0">
        <div
          class="record-item"
          v-for="(record, index) in recordList"
          :key="index"
        >
          <div class="record-line">
            <div class="record-left">
              <div class="amount">
                金额：<span>{{ record.ticketsum }}元</span>
              </div>
            </div>
            <div class="record-right">
              <div class="coupon-code">消费券码：{{ record.ticketno }}</div>
            </div>
          </div>
          <div class="record-line">
            <div class="record-left">
              <div class="operate-time">操作时间：{{ record.createtime }}</div>
            </div>
            <div class="record-right">
              <div class="operator">操作员：{{ record.name }}</div>
            </div>
          </div>
        </div>
      </div>
      <div v-else style="font-size: 16px; text-align: center; height: 80px; line-height: 80px; color: #666;">暂无记录</div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.records-container {
  min-height: 100vh;
  background-size: 100%;
  background-color: #f1f3f4;
  padding-bottom: 20px;
}

.header {
  height: 44px;
  background-color: #f15a4a;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  padding-top: 20px; /* 适配状态栏 */

  .title {
    font-size: 18px;
    font-weight: bold;
  }

  .more-btn {
    position: absolute;
    right: 15px;
    top: 50%;
    transform: translateY(-50%);
    display: flex;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.2);
    border-radius: 20px;
    padding: 5px 10px;

    .dot {
      width: 4px;
      height: 4px;
      background-color: white;
      border-radius: 50%;
      margin: 0 2px;
    }
  }
}

.statistics {
  color: white;
  padding: 15px;

  .stat-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 20px;
  }

  .stat-numbers {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .stat-item {
      display: flex;
      align-items: center;
      justify-content: center;
      img{
        width: 16px;
        margin-right: 5px;
      }
      .stat-icon {
        margin-right: 5px;
        font-size: 16px;
      }

      .stat-text {
        font-size: 14px;
      }
    }
    .today-count,
    .today-amount {
      flex: 1;
      text-align: center;

      .number {
        font-size: 32px;
        font-weight: bold;
        margin-bottom: 5px;
      }

      .label {
        font-size: 12px;
        opacity: 0.8;
      }
    }

    .divider {
      width: 1px;
      height: 40px;
      background-color: rgba(255, 255, 255, 0.3);
    }
  }
}

.record-details {
  margin-top: 10px;
  background-color: white;
  border-radius: 10px 10px 0 0;
  overflow: hidden;

  .detail-title {
    padding: 15px;
    font-size: 16px;
    font-weight: bold;
    color: #333;
    border-bottom: 1px solid #f0f0f0;
    position: relative;
    padding-left: 25px;

    &:before {
      content: "";
      position: absolute;
      left: 15px;
      top: 50%;
      transform: translateY(-50%);
      width: 3px;
      height: 16px;
      background-color: #f15a4a;
    }
  }

  .record-list {
    padding: 0 15px;
  }

  .record-item {
    padding: 15px 0;
    border-bottom: 1px solid #f0f0f0;
    .record-line {
      display: flex;
      justify-content: space-between;
      .record-left {
        .amount {
          font-size: 14px;
          margin-bottom: 5px;
          color: #f15a4a;
        }

        .operate-time {
          font-size: 12px;
          color: #999;
        }
      }

      .record-right {
        text-align: right;

        .coupon-code {
          font-size: 14px;
          margin-bottom: 5px;
        }

        .operator {
          font-size: 12px;
          color: #999;
        }
      }
    }

    &:last-child {
      border-bottom: none;
    }
  }
}
</style>
